package com.seventh.blecore;

import android.app.Activity;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.seventh.blecore.callback.NotifyCallback;
import com.seventh.blecore.callback.ResponseCallback;
import com.seventh.blecore.callback.SearchCallback;

/**
 * @author chengxin
 * create at 2021/4/19
 * description:Unity调用android ble暴露的接口类
 */
public class UnityCallBle implements IUnityCallBle {
    private static UnityCallBle sInstance;
    private final IUnityCallBle mDelegate;

    public synchronized static UnityCallBle getInstance(@NonNull Context context) {
        if (sInstance == null) {
            sInstance = new UnityCallBle(context);
        }
        return sInstance;
    }

    public synchronized static UnityCallBle getInstance() {
        if (sInstance == null) {
            sInstance = new UnityCallBle(Utils.getUnityActivity());
        }
        return sInstance;
    }


    private UnityCallBle(@NonNull Context context) {
        mDelegate = new UnityCallBleImpl((context));
    }

    @Override
    public void setDebug(boolean debug) {
        mDelegate.setDebug(debug);
    }

    @Override
    public void setPostUi(boolean postUi) {
        mDelegate.setPostUi(postUi);
    }

    @Override
    public void setAndroidTestActivity(@NonNull Activity activity) {
        mDelegate.setAndroidTestActivity(activity);
    }

    @Override
    public void searchByAddresses(@Nullable String filterAddresses, int scanTime, boolean showDevicesDialog, @NonNull SearchCallback callback) {
        mDelegate.searchByAddresses(filterAddresses, scanTime, showDevicesDialog, callback);
    }

    @Override
    public void searchByName(@Nullable String filterName, int scanTime, boolean showDevicesDialog, @NonNull SearchCallback callback) {
        mDelegate.searchByName(filterName, scanTime, showDevicesDialog, callback);
    }

    @Override
    public void stopSearch() {
        mDelegate.stopSearch();
    }

    @Override
    public void connect(@NonNull String mac, @NonNull ResponseCallback callback) {
        mDelegate.connect(mac, callback);
    }

    @Override
    public void disconnect(@NonNull String mac) {
        mDelegate.disconnect(mac);
    }

    @Override
    public void notify(@NonNull String mac, @NonNull String service, @NonNull String character, @NonNull NotifyCallback callback) {
        mDelegate.notify(mac, service, character, callback);
    }

    @Override
    public void write(boolean noResponse, @NonNull String mac, @NonNull String service, @NonNull String character, @NonNull byte[] data, @NonNull ResponseCallback callback) {
        mDelegate.write(noResponse, mac, service, character, data, callback);
    }

    @Override
    public int getBondState(@NonNull String mac) {
        return mDelegate.getBondState(mac);
    }

    @Override
    public int getConnectStatus(@NonNull String mac) {
        return mDelegate.getConnectStatus(mac);
    }

    @Override
    public boolean isDeviceConnected(@NonNull String mac) {
        return mDelegate.isDeviceConnected(mac);
    }
}
